- create_paypal_link = link_to(t("paypal_accounts.create_paypal_account_link_text"),
                               presenter.create_url, target: "_blank")
- upgrade_paypal_link = link_to(t("paypal_accounts.upgrade_paypal_account_link_text"),
                                presenter.upgrade_url, target: "_blank")
- paypal_redirect_link = "<a href='#' id='ask_paypal_permissions_redirect'>#{t("paypal_accounts.redirect_link_text")}</a>"

- if !presenter.stripe_enabled
  = render partial: "paypal_accounts/paypal_info", locals: { create_paypal_account_link: create_paypal_link,
      upgrade_paypal_account_link: upgrade_paypal_link,
      paypal_account_linked: presenter.next_action != :ask_order_permission,
      receive_funds_info_label_tr_key: presenter.receive_funds_info_label_tr_key,
      receive_funds_info_tr_key: presenter.receive_funds_info_tr_key,
      commission_required: presenter.commission_type != :none }

- if presenter.next_action == :ask_order_permission
  - content_for :javascript do
    ST.initializeNewPaypalAccountHandler("ask_paypal_permissions", "#{presenter.order_permission_action}", ".js-paypal-redirect-order-permission");

  - if !presenter.stripe_enabled
    .row.paypal-follow-steps
      .col-12
        = t("paypal_accounts.new.follow_steps")

  .row.paypal-wizard
    .col-12
      .paypal-wizard-content
        .row
          .col-12
            %h3.paypal-wizard-step
              =t("paypal_accounts.new.connect_paypal_account_title_with_step", current_step: 1, total_steps: 2)
        .row
          .col-12
            =t("paypal_accounts.new.connect_paypal_account_instructions")
        .row.send-button-wrapper.without-margin
          .col-12
            %button#ask_paypal_permissions
              = t("paypal_accounts.new.connect_paypal_account")
        .row.js-paypal-redirect-order-permission.hidden
          .col-12
            .paypal-redirect-message

              = t("paypal_accounts.redirect_message", redirect_link: paypal_redirect_link).html_safe
- elsif presenter.next_action == :ask_billing_agreement
  - content_for :javascript do
    ST.initializeNewPaypalAccountHandler("ask_billing_agreement", "#{presenter.billing_agreement_action}", ".js-paypal-redirect-billing-agreement");
    ST.initializeNewPaypalAccountHandler("ask_paypal_permissions", "#{presenter.order_permission_action}", ".js-paypal-redirect-change-account");
  - if presenter.commission_type != :none && !presenter.stripe_enabled
    .row.paypal-follow-steps
      .col-12
        = t("paypal_accounts.new.follow_steps")

  .row.paypal-wizard
    .col-12
      - if !presenter.stripe_enabled
        .paypal-wizard-content
          = render partial: "layouts/paypal_account_connected", locals: {paypal_account_email: presenter.paypal_account[:email],
              paypal_redirect_link: paypal_redirect_link}
        .paypal-wizard-divider
      - else
        .paypal-wizard-content
          =t("stripe_accounts.paypal_connected_give_permission", email: presenter.paypal_account[:email])

          .row.paypal-link-wrapper
            .col-12
              %a.paypal-change-link#ask_paypal_permissions
                = t("paypal_accounts.change_account")
        .paypal-wizard-divider

      .paypal-wizard-content
        .row
          .col-12
            %h3.paypal-wizard-step
              = t("paypal_accounts.new.paypal_account_billing_agreement_with_step", current_step: 2, total_steps: 2)
        .row
          .col-12
            - paypal_info_link = "<a id='paypal_fee_info_link' href='#'>#{t("paypal_accounts.new.paypal_info_link_text")}</a>"
            - if presenter.commission_type == :both # TODO: Tweak copy
              = render :partial => "layouts/info_text", :locals => {text: t("paypal_accounts.new.paypal_account_billing_agreement_info_both",
                commission_from_seller: presenter.commission_from_seller,
                minimum_commission: MoneyViewUtils.to_humanized(presenter.minimum_commission),
                paypal_info_link: paypal_info_link).html_safe }
            - elsif presenter.commission_type == :relative
              = render :partial => "layouts/info_text", :locals => {text: t("paypal_accounts.new.paypal_account_billing_agreement_info_relative",
                commission_from_seller: presenter.commission_from_seller,
                paypal_info_link: paypal_info_link).html_safe }
            - elsif presenter.commission_type == :fixed
              = render :partial => "layouts/info_text", :locals => {text: t("paypal_accounts.new.paypal_account_billing_agreement_info_fixed",
                minimum_commission: MoneyViewUtils.to_humanized(presenter.minimum_commission),
                paypal_info_link: paypal_info_link).html_safe }
            - else # no commission fee
              = render :partial => "layouts/info_text", :locals => {text: t("paypal_accounts.new.paypal_account_billing_agreement_info_none",
                paypal_info_link: paypal_info_link).html_safe }
        .row.send-button-wrapper.without-margin
          .col-12
            %button.send_button#ask_billing_agreement
              = t("paypal_accounts.new.billing_agreement")
        .row.js-paypal-redirect-billing-agreement.hidden
          .col-12
            .paypal-redirect-message
              - paypal_redirect_link = "<a href='#' id='ask_billing_agreement_redirect'>#{t("paypal_accounts.redirect_link_text")}</a>"
              = t("paypal_accounts.redirect_message", redirect_link: paypal_redirect_link).html_safe
        = render layout: "layouts/lightbox", locals: { id: "paypal_fee_info_content"} do
          %h2= t("common.paypal_fee_info.title")
          - text_with_line_breaks_html_safe do
            - link_to_paypal = link_to(t("common.paypal_fee_info.link_to_paypal_text"), presenter.paypal_fees_url, target: "_blank")
            = t("common.paypal_fee_info.body_text", link_to_paypal: link_to_paypal,
              paypal_commission: presenter.paypal_commission,
              minimum_transaction_fee: MoneyViewUtils.to_humanized(presenter.minimum_commission)).html_safe

        - content_for :extra_javascript do
          :javascript
            $('#paypal_fee_info_link').click(function() { $('#paypal_fee_info_content').lightbox_me({centered: true, zIndex: 1000000}); });
- else

  - content_for :javascript do
    ST.initializeNewPaypalAccountHandler("ask_paypal_permissions", "#{presenter.order_permission_action}", ".js-paypal-redirect-change-account");
  - if !presenter.stripe_enabled
    .row.paypal-wizard
      .col-12
        .paypal-wizard-content
          .row
            .col-12
              %h3.paypal-wizard-step-complete
                = t("paypal_accounts.paypal_account_all_set_up")
          .row
            .col-12
              =t("paypal_accounts.can_receive_payments")
          .row.paypal-first-steps-list
            .col-12
              =icon_tag("check", ["icon-fix", "paypal-success-mark"])
              =t("paypal_accounts.paypal_account_connected_summary", :email => presenter.paypal_account[:email])
          .row.paypal-last-steps-list
            .col-12
              =icon_tag("check", ["icon-fix", "paypal-success-mark"])
              =t("paypal_accounts.paypal_permission_granted_summary")
          .row.paypal-link-wrapper
            .col-12
              %a.paypal-change-link#ask_paypal_permissions
                = t("paypal_accounts.change_account")
          .row.hidden.js-paypal-redirect-change-account
            .col-12
              .paypal-redirect-message
                - paypal_redirect_link = "<a href='#' id='ask_paypal_permissions_redirect'>#{t("paypal_accounts.redirect_link_text")}</a>"
                = t("paypal_accounts.redirect_message", redirect_link: paypal_redirect_link).html_safe
